package com.example.demo.leetcode.classics150;

import java.util.HashMap;
import java.util.Map;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _44两数之和
 * @description
 * @date 2023/07/22 9:24
 * <p>
 * ******************************************************
 */
public class _44两数之和 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> valueToIndex = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            int key = target - nums[i];
            if (!valueToIndex.containsKey(key)) {
                valueToIndex.put(key, i);
            } else {
                return new int[]{i, valueToIndex.get(key)};
            }
        }
        return null;
    }
}
